/********************************************************************
    copyright (c) by tnmujoy
    @created:	10/19/2011   14:51
    @filename: 	Composite
    @author:	Limiko Lau (limiko.lau@gmail.com)
    @brief:	    
*********************************************************************/

#ifndef TNMUJOY_GDUT_DESIGNPATTERN_COMPOSITE_H_
#define TNMUJOY_GDUT_DESIGNPATTERN_COMPOSITE_H_

namespace tnmujoy
{
namespace gdut
{

template<class T>
class Component
{
public:
    virtual void add(T* _component) = 0;
    virtual void remove(T* _component) = 0;
protected:
    template <class T> friend class Composite;
    void addParent(T* _parent)
    {
        parents_.push_back(_parent);
    }
    std::list<T*> parents_;
};

template<class T>
class Composite : public T
{
public:
    void add(T* _component)
    {
        children_.push_back(_component);
        _component->addParent(this);
    }
    void remove(T* _component)
    {

    }
protected:
    std::list<T*> children_;
};

template<class T>
class Leaf : public T
{
public:
    void add(T* _component)
    {
        assert(false);
    }
    void remove(T* _component)
    {
        assert(false);
    }
protected:
private:
};

}//namespace gdut
}//namespace tnmujoy

#endif //TNMUJOY_GDUT_DESIGNPATTERN_COMPOSITE_H_

//
//History:
//[10/19/2011] <limiko.lau@gmail.com> created